import 'package:enterprise_v6_app/app/core/core.dart';

/// 自定义卡片
class CustomCard extends StatelessWidget {
  const CustomCard({
    required this.content,
    this.title,
    super.key,
    this.titleWidget,
    this.padding,
    this.radius,
    this.divider,
    this.onTap,
    this.titleRight,
    this.color,
  });

  // 标题 String，优先级低于 [titleWidget]
  final String? title;

  /// 标题 Widget，优先级高于 [title]
  final Widget? titleWidget;

  /// 标题右侧 Widget
  final Widget? titleRight;

  // 内容
  final Widget content;

  /// 内边距
  final EdgeInsetsGeometry? padding;

  /// 弧度
  final double? radius;

  /// 标题与内容间的分割线
  final Widget? divider;

  /// 点击回调
  final VoidCallback? onTap;

  final Color? color;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: padding ??
            EdgeInsets.symmetric(
              horizontal: 12.w,
              vertical: 14.w,
            ),
        decoration: BoxDecoration(
          color: color ?? Colors.white,
          borderRadius: BorderRadius.circular((radius ?? 6).w),
        ),
        child: Column(
          children: [
            if (titleWidget != null) titleWidget ?? AppGaps.zero,
            if (title != null && titleWidget == null)
              Row(
                children: [
                  Container(
                    height: 12.w,
                    width: 3.w,
                    decoration: BoxDecoration(
                      color: Colors.blue,
                      borderRadius: BorderRadius.circular(6.w),
                    ),
                  ),
                  AppGaps.hGap10,
                  Expanded(
                    child: Text(
                      title ?? '',
                      style: TextStyle(
                        fontSize: 16.sp,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                  if (titleRight != null) titleRight ?? AppGaps.zero,
                ],
              ),
            if (title != null || titleWidget != null) divider ?? AppGaps.vGap12,
            content,
          ],
        ),
      ),
    );
  }

  static const builtinDivider = Divider(
    height: 1,
    color: AppColors.divider_color_blue,
  );

  static final builtinDividerWithPadding = Padding(
    padding: EdgeInsets.symmetric(vertical: 12.w),
    child: builtinDivider,
  );

  static final Widget leadingSmall = Container(
    decoration: BoxDecoration(
      gradient: const LinearGradient(
        colors: [Color(0xFF5C6DFF), Color(0xFFB0ABFB)],
        begin: Alignment.topCenter,
        end: Alignment.bottomCenter,
      ),
      borderRadius: BorderRadius.circular(3.w),
    ),
    height: 12.w,
    width: 4.w,
  );
}
